package com.acme.team3.chat;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Command {
	private String cmd;
	private String arg;

	private static Pattern cmdPat = Pattern.compile("/(?<cmd>[A-Za-z]+)");
	private static Pattern cmdArgPat = Pattern.compile("/(?<cmd>[A-Za-z]+) (?<arg>.+)");
	
	public static String INCORRECT_COMMAND = "INCORRECT_COMMAND";
	
	public Command(String str) {
		Matcher m = cmdPat.matcher(str);
		if (m.matches()) {
			cmd = m.group("cmd");
			arg = null;
		} else if ((m = cmdArgPat.matcher(str)).matches()) {
			cmd = m.group("cmd");
			arg = m.group("arg");
		} else {
			cmd = INCORRECT_COMMAND;
		}
	}
	
	public String getCmd() {
		return cmd;
	}
	public String getArg() {
		return arg;
	}
	
}
